package com.xhs.minio.core.utils;

import com.xhs.minio.core.exception.CommonException;
import com.xhs.minio.core.message.Result;

/**
 * @desc: 异常工具类
 * @projectName: spring-boot-minio
 * @author: xhs
 * @date: 2025-08-16 周六 17:04
 */
public class ThrowUtil {

    /**
     * 条件成立则抛异常
     *
     * @param condition        条件
     * @param runtimeException 异常
     */
    public static void throwIf(boolean condition, RuntimeException runtimeException) {
        if (condition) {
            throw runtimeException;
        }
    }

    /**
     * 条件成立则抛异常
     *
     * @param condition 条件
     * @param errorCode 错误码
     */
    public static void throwIf(boolean condition, Result errorCode) {
        throwIf(condition, new CommonException(errorCode));
    }

    /**
     * 条件成立则抛异常
     *
     * @param condition 条件
     * @param errorCode 错误码
     * @param message   错误信息
     */
    public static void throwIf(boolean condition, Result errorCode, String message) {
        throwIf(condition, new CommonException(errorCode, message));
    }

    /**
     * 条件成立则抛异常
     *
     * @param condition 条件
     * @param errorCode 错误码
     * @param message   错误信息
     */
    public static void throwIf(boolean condition, Result errorCode, String message,Object... arguments) {
        throwIf(condition, new CommonException(errorCode, message,arguments));
    }
}
